-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Online DDL: revert considerations for migrations with foreign key constraints #14368
Online DDL: revert considerations for migrations with foreign key constraints #14368
Conversation
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
Signed-off-by: Shlomi Noach <[email protected]>
Up to 7cee6d3, we deal with two situations that are actually manifestations of the same concept: dropping a foreign key. When you drop a foreign key, you drop a constraint. When a constraint is dropped, your data becomes less constrained, and it is then possible for the data to take forms it could not, before. This is why reverting the drop of a foreign key is a problem: you reintroduce a constraint, and the data may already disagree with the constraint. Moving on:
More thinking to come. |
Noteworthy: at this time Vitess does not prevent the scenario where a FK parent table is First, they are So at this time this is not being handled, and we assume that a child table gets dropped (or its foreign key constraints are dropped), before the parent table is dropped. This is one of the reasons why the DDL strategy flag that allows foreign keys starts with " |
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
At this time I'm only able to see risks with all things removing-a-foreign-key. To that effect, I'm making this PR ready to review. We can iterate in the future in case we meet new scenarios. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a great read! Thank you 🙏
Description
This PR maps what kind of migrations, that deal with foreign keys, have revertibility risks.
As an obvious example: imagine
DROP
ping a FK child table. Then, as the parent has no children, youDELETE
all rows from the parent. Then, you revert theDROP
. The child table re-appears with rows that have no compatible rows in the parent.This is but one example and this PR investigates the potential of other types of migrations to cause FK violation.
It should be noteworthy that FK violation in MySQL is generally in the user's hands. It is always possible, in MySQL, to
SET FOREIGN_KEY_CHECKS=0
and introduce violations. The server does not blow up, it's just that enforcement is suspended.Related Issue(s)
Checklist
Deployment Notes